/*
   Copyright (c) 2019 Shanghai Xuanzi Technology Co. Ltd https://xuanzi.ltd
   XZMindMap is licensed under the Mulan PSL v1.
   You can use this software according to the terms and conditions of the Mulan PSL v1.
   You may obtain a copy of Mulan PSL v1 at:
      http://license.coscl.org.cn/MulanPSL
   THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
   PURPOSE.
   See the Mulan PSL v1 for more details.

*/

package xuanzi.commons.graphics;

import xuanzi.openmind.nodes.ShapeUtils;

public class Line {

	public Line() {
		// TODO Auto-generated constructor stub
	}
	
	public PointF a,b;
	
	public static Line toRect(PointF point ,BoxF target) {
		Line line = new Line();
		if(point.y<target.centerY()) {
			line.a = point;
			line.b = ShapeUtils.intersectPoint(line.a,new PointF(target.centerX(),target.centerY()),new PointF(target.left, target.top), new PointF(target.right,target.top));
			
		}else {
			line.a = point;
			line.b = ShapeUtils.intersectPoint(line.a,new PointF(target.centerX(),target.centerY()),new PointF(target.left, target.bottom), new PointF(target.right,target.bottom));
			
		}
		
		return line;
	}

	public static Line toRect(BoxF start ,BoxF target) {
		Line line = new Line();
		PointF alt = new PointF(start.left, start.top);
		PointF art = new PointF(start.right, start.top);
		PointF alb = new PointF(start.left, start.bottom);
		PointF arb = new PointF(start.right, start.bottom);
		
		PointF blt = new PointF(target.left, target.top);
		PointF brt = new PointF(target.right, target.top);
		PointF blb = new PointF(target.left, target.bottom);
		PointF brb = new PointF(target.right, target.bottom);
		
		PointF ac = new PointF(start.centerX(),start.centerY());
		PointF bc = new PointF(target.centerX(),target.centerY());
		
		
		if(start.centerY()<target.centerY()) {
			line.a = ShapeUtils.intersectPoint(bc,ac,alb, arb);;
			line.b = ShapeUtils.intersectPoint(ac,bc,blt,brt);
			
		}else {
			line.a = ShapeUtils.intersectPoint(bc,ac,alt, art);;
			line.b = ShapeUtils.intersectPoint(ac,bc,blb,brb);
		}
		
		return line;
	}
}
